package com.authine.cloudpivot.common;

import com.alibaba.cola.dto.Response;
import com.alibaba.cola.dto.SingleResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.EnvironmentAware;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author carter
 * create_date  2020/6/4 19:02
 * description     健康检查接口
 */
@Api(tags = "公共服务::健康检查")
@RestController
@Slf4j
public class HealthController implements EnvironmentAware {

    @Value("${spring.application.name}")
    private String applicationName;

    private Environment environment;

    @ApiOperation("回声检测")
    @GetMapping("/echo")
    public Response echo() {
        return SingleResponse.of(applicationName);
    }


    @ApiOperation("测试获取公共配置文件")
    @GetMapping("/config/test")
    public Response config() {
        String redisConfigServers = environment.getProperty("redis.config.servers", "null");
        return SingleResponse.of(redisConfigServers);
    }

    /**
     * Set the {@code Environment} that this component runs in.
     *
     * @param environment
     */
    @Override
    public void setEnvironment(Environment environment) {
        this.environment = environment;
    }

}
